package com.example.routelink.gateway.filter;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RewriteStackTraceResponseBodyFilterGatewayFilterFactory extends BaseFilter<RewriteStackTraceResponseBodyFilterGatewayFilterFactory.Config> implements Ordered {
    public RewriteStackTraceResponseBodyFilterGatewayFilterFactory() {
        super(RewriteStackTraceResponseBodyFilterGatewayFilterFactory.Config.class);
    }
    public static final String RES_IS_STACK_TRACE = "RES_IS_STACK_TRACE";

    @Override
    public GatewayFilter apply(RewriteStackTraceResponseBodyFilterGatewayFilterFactory.Config config) {
        return (exchange, chain) -> {
            exchange.getAttributes().put(RES_IS_STACK_TRACE, true);
            return chain.filter(exchange);
        };
    }

    @Override
    public int getOrder() {
        return Ordered.HIGHEST_PRECEDENCE;
    }


    @Data
    public static class Config {
    }
}
